import sys
data = [['is', 'was', 'been'],
        ['are', 'were', 'been'],
        ['has', 'had', 'had'], 
        ['have', 'had', 'had']
        ]
#vowel
VOWEL = ['a', 'o', 'u', 'e', 'i']
ENDING_ES_ADD = ['x', 'sh', 's', 'ss', 'ch']

IRREGULAR_PLURAL = [['goose', 'geese'],
                    ['man', 'men'],
                    ]

from collections import deque
#States
_VERB = 0
_NOUN = 1
_ADJ = 2
_ADV = 3
_VSPAST = 4
_VPP = 5
_NPLURAL = 6

#links
STATE_FUL = 0
STATE_MENT = 1
STATE_ITY = 2
STATE_LY = 3
STATE_EN = 4
STATE_DIS = 5
STATE_UN = 6
STATE_IN = 7
STATE_INTER = 8
STATE_ATION = 9
STATE_EE = 10
STATE_ER = 11
STATE_AL = 12
STATE_ABLE = 13
STATE_LESS = 14
STATE_NESS = 15
STATE_PAST_PRESENT =  16
STATE_PRESENT_PAST = 17
STATE_R_FUL = 18
STATE_R_LY = 19
STATE_PLURAL = 24
STATE_SINGLE = 25

#conlict
FSA_CONFLICT = [[STATE_NESS,STATE_LESS],
                [STATE_NESS,STATE_AL],
                [STATE_EE,STATE_AL],
                [STATE_EE,STATE_LESS],
                [STATE_ER,STATE_AL],
                [STATE_ER,STATE_FUL],
                [STATE_EE,STATE_FUL],
                [STATE_PAST_PRESENT, STATE_PRESENT_PAST],
                [STATE_LESS,STATE_PLURAL],
                [STATE_NESS,STATE_PLURAL],
                [STATE_R_FUL,STATE_FUL],
                [STATE_R_LY,STATE_LY]
                ]

#available link
FSA = [[_VERB,STATE_ATION],
       [_VERB,STATE_EE],
       [_VERB,STATE_ER],
       [_VERB,STATE_ABLE],
       [_ADJ,STATE_NESS],
       [_NOUN,STATE_AL],
       [_NOUN,STATE_LESS],
       [_NOUN,STATE_FUL],
       [_VSPAST,STATE_PAST_PRESENT],
       [_VERB,STATE_PRESENT_PAST],
       [_NOUN,STATE_PLURAL],
       [_NPLURAL,STATE_SINGLE],
       [_ADJ,STATE_R_FUL],
       [_ADJ,STATE_LY],
       [_ADV,STATE_R_LY]]

def isEnd(word, end):
    if word[-len(end):] == end.lower():
        return True
    else:
        return False


class WordState:
    def __init__(self, inputWord, inputState , inputOld, inputType):
        self.word = inputWord.lower()
        self.type = inputType
        self.old = []
        if inputState != None:
            self.state = inputState
            self.old = inputOld
        else:
            self.state = []
            if self.word.find("ful") >= 0:
                self.old.append(STATE_FUL)
            if self.word.find("ly") >= 0:
                self.old.append(STATE_LY)
            
    def checkConflict(self, newState):
        if newState in self.state:
            return True
        if newState in self.old:
            return True
        for conflict in FSA_CONFLICT:
            if (newState == conflict[0]) & (conflict[1] in self.state):
                return True
            if (newState == conflict[1]) & (conflict[0] in self.state):
                return True
        return False
    
    def isEnd(self, end):
        if self.word[-len(end):] == end.lower():
            return True
        else:
            return False

    def isBegin(self, begin):
        if self.word[:len(begin)] == begin.lower():
            return True
        else:
            return False

    def remove_e(self):
        if self.word[-1] == 'e':
            return WordState(self.word[:-1],self.state,self.old,self.type)
        return self
    def change_y(self):
        tmpWord = self.word
        if self.word.endswith('y') and (not tmpWord[-2] in VOWEL):
            return WordState(self.word[:-1]+"i",self.state,self.old,self.type)
        return self
    def restore_y(self):
        tmpWord = self.word
        if self.word.endswith('i') and (not tmpWord[-2] in VOWEL):
            return WordState(self.word[:-1]+"y",self.state,self.old,self.type)
        return self

    def add_ful(self):
        return WordState(self.word+"ful",self.state+[STATE_FUL],self.old,_ADJ)
    def add_ment(self):
        return WordState(self.word+"ment",self.state+[STATE_MENT],self.old,_NOUN)
    def add_ity(self):
        return WordState(self.word+"ity",self.state+[STATE_ITY],self.old,_NOUN)
    def add_ly(self):
        return WordState(self.word+"ly",self.state+[STATE_LY],self.old,_ADV)
    def add_en(self):
        return WordState(self.word+"en",self.state+[STATE_EN],self.old,_VERB)
    def add_dis(self):
        return WordState("dis"+self.word,self.state+[STATE_DIS],self.old,self.type)
    def add_un(self):
        return WordState("un"+self.word,self.state+[STATE_UN],self.old,self.type)
    def add_in(self):
        return WordState("in"+self.word,self.state+[STATE_IN],self.old,self.type)
    def add_inter(self):
        return WordState("inter"+self.word,self.state+[STATE_INTER],self.old,self.type)
    def add_ation(self):
        return WordState(self.word+"ation",self.state+[STATE_ATION],self.old,_NOUN)
    def add_ee(self):
        return WordState(self.word+"ee",self.state+[STATE_EE],self.old,_NOUN)
    def add_er(self):
        return WordState(self.word+"er",self.state+[STATE_ER],self.old,_NOUN)
    def add_ness(self):
        return WordState(self.word+"ness",self.state+[STATE_NESS],self.old,_NOUN)
    def add_al(self):
        return WordState(self.word+"al",self.state+[STATE_AL],self.old,_ADJ)
    def add_able(self):
        return WordState(self.word+"able",self.state+[STATE_ABLE],self.old,_ADJ)
    def add_less(self):
        return WordState(self.word+"less",self.state+[STATE_LESS],self.old,_ADJ)
    def remove_ful(self):
        if not self.word.endswith("ful"):
            return None 
        return WordState(self.word[:-3],self.state+[STATE_R_FUL],self.old,_NOUN).restore_y()
    def remove_ly(self):
        if not self.word.endswith("ly"):
            return None 
        return WordState(self.word[:-2],self.state+[STATE_R_LY],self.old,_ADJ).restore_y()

    
    def toPlural(self):
        if (len(self.state)>0) and (self.state[len(self.state)-1] == STATE_SINGLE):
            return
        tmpWord = self.word
        if tmpWord.endswith('y'):
            if tmpWord[-2] in VOWEL:
                tmpWord = tmpWord
            else:
                tmpWord = tmpWord[:-1] + 'ie'
        elif isEnd(tmpWord, 'f'):
            tmpWord = tmpWord[:-1] + 've'
        else:
            for i in ENDING_ES_ADD:
                if isEnd(tmpWord, i):
                    tmpWord = tmpWord + 'e'
                    break
        return WordState(tmpWord + 's',self.state+[STATE_PLURAL],self.old,_NPLURAL)
    
    def toSingle(self):
        if (len(self.state)>0) and (self.state[len(self.state)-1] == STATE_PLURAL):
            return
        tmpWord = self.word
        if isEnd(tmpWord, 'ies'):
            tmpWord = tmpWord[:-3]+'y'
        elif isEnd(tmpWord, 'ves'):
            tmpWord = tmpWord[:-3]+ 'f'
        elif isEnd(tmpWord, 'es'):
            tmpWord = tmpWord[:-2]
        else:
            tmpWord = tmpWord[:-1]
        return WordState(tmpWord,self.state+[STATE_SINGLE],self.old,_NOUN)

#Dat    
    def past_present(self):
        for row in data:
            if row[1] == self.word:
                return WordState(row[0], self.state +[STATE_PAST_PRESENT],self.old,_VERB)
        if(self.word[-1] =='d' and self.word[-2] == 'e'):
            #print ('convert past-> present simple')
            return WordState(self.word[:-2], self.state +[STATE_PAST_PRESENT],self.old,_VERB)
        
#Dat        
    def present_past(self):
        for row in data:
            if row[0] == self.word:
                return WordState(row[1], self.state +[STATE_PAST_PRESENT],self.old,_VSPAST)
        if (self.word[-1] == 'e'):         
            return WordState(self.word +'d', self.state +[STATE_PAST_PRESENT],self.old,_VSPAST)
            #  end by y  
        if (self.word[-1] == 'y'):
            return WordState(self.word[:-1]+'ied', self.state +[STATE_PAST_PRESENT],self.old,_VSPAST)
        
    # processing by adding new state
    def transducer(self,newState):
        if self.checkConflict(newState):
            return None
        if newState == STATE_ATION:
            return self.remove_e().change_y().add_ation()
        elif newState == STATE_EE:
            return self.remove_e().change_y().add_ee()
        elif newState == STATE_ER:
            return self.remove_e().change_y().add_er()
        elif newState == STATE_NESS:
            return self.change_y().add_ness()
        elif newState == STATE_AL:
            return self.remove_e().change_y().add_al()
        elif newState == STATE_ABLE:
            return self.remove_e().change_y().add_able()
        elif newState ==STATE_LESS:
            return self.change_y().add_less()
        elif newState == STATE_FUL:
            return self.change_y().add_ful()
        elif newState == STATE_MENT:
            return self.change_y().add_ment()
        elif newState == STATE_ITY:
            return self.remove_e().change_y().add_ity()
        elif newState == STATE_PAST_PRESENT:
            return self.past_present()
        elif newState == STATE_PRESENT_PAST:
            return self.present_past()
        elif newState == STATE_PLURAL:
            return self.toPlural()
        elif newState == STATE_SINGLE:
            return self.toSingle()
        elif newState == STATE_R_FUL:
            return self.remove_ful()
        elif newState == STATE_LY:
            return self.change_y().add_ly()
        elif newState == STATE_R_LY:
            return self.remove_ly()
        
    
result = []

def find_all_words(inputWord):
    # break if there is no word
    if inputWord == None:
        return
    result.append(inputWord.word)
    #print inputWord.word
    #print STATE_ATION in inputWord.state
    # search in FSA
    for link in FSA:
        #print link[0],link[1]
        if link[0] == inputWord.type:
            find_all_words(inputWord.transducer(link[1]))
    
#inputWord = WordState(sys.argv[1],None,_VERB)
"""
inputWord = WordState("friend",None,_NOUN)
find_all_words(inputWord)

print result

"""
def main():
    inputWord = WordState(sys.argv[1],None,_VERB)
    #inputWord = WordState("compute",None,None,_VERB)

    find_all_words(inputWord);
    print result
    return 0

if __name__ == '__main__':
    main()